//方式1  不从后台获取
function editEmp(rows) {
    $("#h4").text("修改员工")
    $("#empno").val(rows.empno);
    $("#ename").val(rows.ename);
    $("#job").val(rows.job);
    $("#sal").val(rows.sal);
    let s = rows.hiredate.substr(0,10);
    $("#hiredate").val(s);
    $("#deptno").val(rows.deptno);
}
//方式2  根据id查询
function editRow(thiseven,empno){
    $("#h_text").html("修改员工");
    $("#empno").val(empno);
        $.ajax({
            type:"get",
            dataType:"json",
            url:"/findEmployeeId?id=" + empno,
            success:function (data) {
                $.each(data,function (name,value) {
                    if(name=='ename'){
                        $("#enames").val(value);
                    }
                    if(name=='job'){
                        $("#job").val(value);
                    }
                    if(name=='sal'){
                        $("#sal").val(value);
                    }
                    if(name=='hiredate'){
                        let now = new Date(value);
                        //格式化日，如果小于9，前面补0
                        var day = ("0" + now.getDate()).slice(-2);
                        //格式化月，如果小于9，前面补0
                        var month = ("0" + (now.getMonth() + 1)).slice(-2);
                        //拼装完整日期格式
                        var today = now.getFullYear()+"-"+(month)+"-"+(day) ;//拼装完整日期格式

                        $("#hiredate").val(today);
                    }
                    if(name=='deptno'){
                        $("#sel1 option").each(function(index, item){
                            if(item.value == value){
                                item.selected = true;
                                return false;
                            }
                        });
                    }
                })
            }
        });

}
function addshow() {
    $("#h_text").html("添加员工");
    //重置表单
    $("#employeeInfo")[0].reset();
}
function saveEmpinfo() {
    let  jsonStr = getFormData($("#employeeInfo"));
    console.log(jsonStr);
    $.ajax({
        type:"post",
        dataType:"json",
        data:jsonStr,
        contentType:"application/json",
        url:"/updateEmployeeId",
        success:function (data) {
            if (data != 0) {
                $("#myModal").modal("hide"); // 隐藏模态框
                $('#table').bootstrapTable('refresh');
            }
        }
    });
}
